package com.allen.controller;

import com.allen.bean.Student;
import com.allen.bean.User;
import com.allen.service.Operation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginuser")
public class Login extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username = req.getParameter("username");
        String pwd = req.getParameter("pwd");

        int id = new Operation().login(username, pwd);
        if (id != 0) {
            new Operation().updatetime(id);
            User user = new Operation().findUserById(id);
            req.getSession().setAttribute("user", user);
            resp.getWriter().print(1);
        } else {
            resp.getWriter().print(0);
        }
    }
}
